package org.fastiot.data.archives

import org.fastiot.data.DataSet

class Latest {

    static mapWith = "mongo"

    String terminalCode
    Date dateAcquired

    DataSet dataSet
    List<Map> metadata
    List<Serializable> contents
    static embedded = ['dataSet', 'metadata', 'contents']

    Date dateCreated
    Date lastUpdated

    static constraints = {
        terminalCode(blank: false)
        dataSet(nullable: false)
        dateAcquired(nullable: false, unique: ["terminalCode", "dataSet"])
        metadata(nullable: false)
        contents(nullable: false)
        dateCreated()
        lastUpdated()
    }

    static mapping = {
        version false
        collection "latestArchives"
        compoundIndex terminalCode: 1, "dataSet.code": 1, dateAcquired: -1
    }
}
